package org.fastiot.gateway.server

import org.apache.camel.Exchange
import org.fastiot.gateway.Message
import org.fastiot.gateway.SessionHolder

class MessageProcessor {
    void receive(Exchange exchange) {
        def msg = exchange.in.getBody(Message)
        println "server.receive:${msg.contents.encodeHex()}"

        reply(exchange)
    }

    void reply(Exchange exchange) {
        def msg = exchange.in.getBody(Message)
        println "server.reply:${msg.contents.encodeHex()}"

        SessionHolder.send(msg.metadata.remoteAddress as InetSocketAddress, msg)
    }
}
